package com.zja.servlet;


import com.zja.model.JsonResponse;
import com.zja.service.ArticleService;
import com.zja.service.Impl.ArticleServiceImpl;
import com.zja.util.ServletUtil;


import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
/**
 * @author JA
 * @date: 2025/5/4
 * description:删除文章
 */
@WebServlet("/api/article/delete")
public class DeleteArticleServlet extends HttpServlet {
    private final ArticleService articleService = new ArticleServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        Long id = Long.valueOf(req.getParameter("id"));
        boolean success = articleService.deleteArticle(id);

        if (success) {
            ServletUtil.writeJsonResponse(resp, JsonResponse.success("删除成功"));
        } else {
            ServletUtil.writeJsonResponse(resp, JsonResponse.error("删除失败"));
        }
    }
}
